package com.qf.controller;

import com.qf.pojo.User;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.logging.Logger;

@Controller
@RequestMapping("/users")
public class UserController {
    @Autowired
    private UserService userService;
    //springMvc会注入这个对象, 因为request, response, sesson, model是spirngmvc的默认支持参数
    //@Autowired
    //private HttpServletRequest request;
    //使用log4j的Logger对象
    //Logger logger = Logger.getLogger(UserController.class);


    //查询所有用户数据返回
    @RequestMapping("/list")
    public String userList(Model model){
        //可以在开发阶段使用打印debug信息


        //1. 调用service查询
        List<User> list = userService.findByNameAndSexAndBirthday();
        //2. 将数据放入model中返回给页面展示
        model.addAttribute("users",list);
        //3. 指定页面位置
        return "user";
    }

}
